//
// Description: 803. 区间合并
// Created by Loading on 2021/12/5.
//

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;

int main() {
    int n;
    cin >> n;
    vector<PII> vec;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        vec.emplace_back(PII{l, r});
    }

    sort(vec.begin(), vec.end());

    // 维护的右端点
    int end = INT_MIN;
    int res = 0;
    for (auto &v : vec) {
        if (v.first > end) {
            // 新的合并区间
            ++res;
            end = v.second;
        } else {
            // 更新右端点
            end = max(end, v.second);
        }
    }
    cout << res << endl;

    return 0;
}